<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <AccountSelect v-model="filter.id" />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button class="fl"  size="small" @click="app.resetFields($refs['filter'].$parent,'filter')">清 空</el-button>
          <el-button class="fl" type="primary" size="small" @click="getList()">查 询</el-button>
          <el-button class="fl" 
            type="primary"
            size="small"
            @click="handleDialog({dRef: 'dialog', dTitle: '新增资金账户', dType: 'add', dField: dField})"
          >新 增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="fl mb20">
      <div class="fl t-div" style="background-color: rgb(41, 156, 205);">
        <div class="t-div-d fs12">当日余额</div>
        <div class="t-div-m fs18">{{ app.toFix(amount.initial_money + amount.inflow_money - amount.outflow_money, 2) }}</div>
      </div>
      <div class="fl t-div" style="background-color: rgb(62, 71, 64);">
        <div class="t-div-d fs12">昨日余额</div>
        <div class="t-div-m fs18">{{ app.toFix(amount.initial_money + amount.yesterday_inflow_money - amount.yesterday_outflow_money, 2) }}</div>
      </div>
      <div class="fl t-div" style="background-color: rgb(117, 208, 92);">
        <div class="t-div-d fs12">当月流入</div>
        <div class="t-div-m fs18">{{ app.toFix(amount.inflow_money, 2) }}</div>
      </div>
      <div class="fl t-div" style="background-color: rgb(225, 169, 27);">
        <div class="t-div-d fs12">当月流出</div>
        <div class="t-div-m fs18">{{ app.toFix(amount.outflow_money, 2) }}</div>
      </div>
    </div>
    <el-table :summary-method="getSummariesList" show-summary ref="multipleTable" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="公司抬头" width="360px" prop="company" />
      <el-table-column label="账户名称" width="290px" prop="name" />
      <el-table-column label="账号" min-width="220px" prop="account" />
      <el-table-column label="余额" align="right" width="200px">
        <template slot-scope="{row}">
          {{ app.toFix(row.initial_money + row.inflow_money - row.outflow_money, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="置顶" align="center" width="110px">
        <template slot-scope="{row}">
          <el-switch
            @change="switchChange(row)"
            v-model="row.top"
            :active-value="1"
            :inactive-value="0">
        </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleDialog({...row, ...{dRef: 'dialog', dTitle: '编辑资金账户', dType: 'edit', dField: dField}})">编 辑</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import page from '@/utils/page'
import Dialog from './components/account-dialog'
import { accounts, topAccount, amountStatistics } from '@/api/finance/fund'
import AccountSelect from '@/myComponents/AccountSelect'

export default {
  name: '',
  components: { Dialog, AccountSelect },
  extends: page,
  props: {
    reqList: {
      default: accounts,
      type: Function
    },
    reqUpd: {
      default: topAccount,
      type: Function
    }
  },
  data() {
    return {
      amount: {},
      price: 0,
      dField: ['id', 'name', 'company', 'type', 'dept_id', 'initial_money', 'initial_date', 'remark', 'account']
    }
  },
  created() {
    this.getList()
  },
  methods: {
    switchChange(e) {
      this.handleEdit({id: e.id}).then(e => {
        this.getList()
      })
    },
    getListAfter() {
      amountStatistics({...this.filter}).then(res => {
        this.amount = res.info || {}
      }).catch(err => {
        this.$message.error(err.msg ? err.msg : '获取数据失败')
        this.app.removeLoding()
      })
      let price = 0
      this.list.forEach(e => {
        price += (e.initial_money + e.inflow_money - e.outflow_money)
      })
      this.price = price
    },
    getSummariesList() {
      const sums = []
      sums[0] = '合计'
      sums[1] = ''
      sums[2] = ''
      sums[3] = ''
      sums[4] = this.app.toFix(this.price, 2)
      return sums
    }
  }
}
</script>
<style scoped>
.t-div{
  height: 100px;
  width: 200px;
  color: #fff;
  border-radius: 6px;
  margin-right: 20px;
}
.t-div-d{
  padding: 25px 0 0 20px;
  width: 200px;
}
.t-div-m{
  padding: 10px 0 0 20px;
  width: 200px;
}
</style>
